package com.mall.b2c.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mall.b2c.service.StockNoticeService;
import com.mall.b2c.util.JsonDataGridHelper;
import com.mall.common.bean.Pager;
import com.mall.common.bean.SearchFilter;
import com.mall.common.controller.BaseController;
import com.mall.common.util.ResponseUtils;
import com.mall.common.validation.annotation.RequiredFieldValidator;
import com.mall.common.validation.annotation.Validations;
import com.mall.common.web.Servlets;

/**
 * 到货通知
 * @author lzx
 *
 */
@Controller
@RequestMapping("/admin/b2c/stockNotice")
public class StockNoticeController extends BaseController{
	
	@Resource private StockNoticeService stockNoticeService;
	
	@RequestMapping("/list")
	public String list(Model model) {
		return "/admin/b2c/stocknotice/list";
	}
	
	@RequestMapping(value="/queryData")
	@ResponseBody
	public Pager queryData(Pager pager, HttpServletRequest request) {
		Map<String, Object> filterParams = Servlets.getParametersStartingWith(request);
		List<SearchFilter> filters = SearchFilter.parse(filterParams);
		pager = stockNoticeService.findPage(pager, filters);
		return JsonDataGridHelper.createJSONData(pager);
	}
	
	@Validations(
			requiredFields = { 
				@RequiredFieldValidator(fieldName = "ids", message = "信息不存在")
			}
	)
	@RequestMapping("/delete")
	public String delete(Long[] ids, HttpServletResponse response) {
		stockNoticeService.remove(ids);
		return ResponseUtils.renderJSON(successMessage, response);
	}
}
